/*
 * Task.java
 *
 * Created on February 3, 2008, 2:21 PM
 *
 */

package projectprophet.core;

import java.util.HashSet;

/**
 *
 * @author Gyula Szentirmay
 */
public abstract class Task
{
	public final String getName()
	{
		return name;
	}
	
	public final int getWorkAmount()
	{
		return workAmount;
	}
	
	public final int getWorkDone()
	{
		return workDone;
	}
	
	public boolean isAssigned(Developer developer)
	{
		return developers.contains(developer);
	}
	
	public Iterable<Developer> getAssignedDevelopers()
	{
		return developers;
	}
	
	public void setName(String newName)
	{
		name = newName;
	}
	
	public void setWorkAmount(int newWorkAmount)
	{
		workAmount = newWorkAmount;
		onChange();
	}
	
	public void setWorkDone(int newWorkDone)
	{
		workDone = newWorkDone;
		onChange();
	}
	
	public void assignDeveloper(Developer developer)
	{
		developers.add(developer);
		onChange();
	}
	
	public void removeDeveloper(Developer developer)
	{
		developers.remove(developer);
		onChange();
	}

	protected void onChange(){}
	
	// internal
	
	protected Task()
	{
		name = "Task "+getIndex();
	}

	protected abstract int getIndex();

	private String name;
	private int workAmount = 0;
	private int workDone = 0;
	private HashSet<Developer> developers = new HashSet<Developer>();
}
